<layout name="page" />
<block name="content">
	<style>
		.avtar {
			width: 80px;
			height: 80px;
		}
	</style>
	<input type="hidden" name="ajax" id="ajax" value="1">
	<select name="dept_list" id="dept_list" class="hidden">
		{:fill_option($dept_list)}
	</select>
	{:widget('page_header/search',array('name'=>'用户管理'))}
	<form method="post" id="form_adv_search" name="form_adv_search" method="post" style="width: 100%;display: flex;" >
		<div class="operate-panel">
			<label class="label w6">状态:</label>
			<div class="input-box w10" style="margin-right: 4px;">
				<select id="eq_is_del" name="eq_is_del" class="select" >
					<option value="0">启用</option>
					<option value="1">禁用</option>
					<option value="2">其他</option>
				</select>
				<i class="icon"></i>
			</div>
			<a class="btn btn-normal" onclick="import_user()">导入</a>
			<a class="btn btn-normal" onclick="sync_to_weixin()">同步到微信</a>
			<a class="btn btn-normal" onclick="reset_password()">设置密码</a>
			<a class="btn btn-normal" onclick="reset_salary_password()">重置工资密码</a>
			<i class="mid"></i>
			<a class="btn btn-normal" onclick="add()">新增</a>
			<a class="btn btn-normal" onclick="save()">保存</a>
			<i class="split"></i>
			<a class="btn btn-del" onclick="del()">删除</a>
		</div>
	</form>
	<div class="x1 sub box">
		<div class="w30 m100">
			<form id="form_user" name="form_user" method="post" >
				<div class="table">
					<ul>
						<li class="thead" >
							<span class="w3" ><label class="checkbox">
									<input type="checkbox" class="toggle-select-all" data="user_id[]"  />
									<i class="icon"></i></label></span>
							<span class="w10" >员工编号</span>
							<span class="w10" >姓名</span>
							<span class="x1">状态</span>
						</li>
						<foreach name="list" val="data">
							<li class="tbody" data="{$data.id}">
								<span class="w3" ><label class="checkbox" >
										<input type="checkbox" name="user_id[]" value="{$data.id}" />
										<i class="icon"></i></label></span>
								<span class="w10">{$data.emp_no}</span>
								<span class="w10 ">{$data.name}</span>
								<span class="x1">{:status($data['is_del'])}</span>
							</li>
						</foreach>
					</ul>
				</div>
			</form>
			{$page}
		</div>
		<div style="width:16px;"></div>
		<div class="x1 frame" style="height:720px;">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" id="save_name" name="save_name">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="signature" id="signature" >
				<input type="hidden" name="opmode" id="opmode" value="edit">
				<div class="box">
					<label class="input-label">头像:</label>
					<img id="pic" class="avtar" src="" onclick="select_avatar()">
				</div>
				<div class="box">
					<label class="input-label">员工编号*：</label>
					<input class="input w19" type="text" id="emp_no" name="emp_no"  check="required" info="请输入员工编号" readonly="readonly">
				</div>
				<div class="box">
					<label class="input-label">姓名*：</label>
					<input class="input w19" type="text" id="name" name="name"  check="required" info="请输入姓名" >
				</div>
				<div class="box">
					<label class="input-label">性别*：</label>
					<select name="sex" id="sex" class="select w10">
						<option  value="male">男</option>
						<option value="female">女</option>
					</select>
					<i class="icon"></i>
				</div>
				<div class="box">
					<label class="input-label">生日*：</label>
					<input  type="text" id="birthday" name="birthday"  class="input-date input" >
				</div>
				<div class="box">
					<label class="input-label">部门*：</label>
					<div class="input-box w19">
						<input name="dept_id" id="dept_id" type="hidden" />
						<input class="input " name="dept_name"  id="dept_name" type="text" info="请选择部门" check="required"  />
						<a class="add-on w4" onclick="select_dept()"><i class="fa fa-search" ></i> </a>
					</div>
				</div>
				<div class="box">
					<label class="input-label">职位*：</label>
					<select name="position_id" id="position_id" class="select w19" info="请选择职位" check="required">
						<option value="">选择职位</option>
						{:fill_option($position_list)}
					</select>
					<i class="icon"></i>
				</div>
				<div class="box">
					<label class="input-label">办公室电话*：</label>
					<input type="text" id="office_tel" name="office_tel" class="input w19">
				</div>
				<div class="box">
					<label class="input-label">移动电话*：</label>
					<input type="text" id="mobile_tel" name="mobile_tel" class="input w19">
				</div>
				<div class="box">
					<label class="input-label">电子邮箱*：</label>
					<input type="text" id="email" name="email" class="input w19">
				</div>
				<div class="box">
					<label class="input-label">负责业务*：</label>
					<input type="text" id="duty" name="duty" class="input">
				</div>
				<div class="box">
					<label class="input-label">状态*：</label>
					<select class="select w10"  name="is_del" id="is_del">
						<option  value="0">启用</option>
						<option value="1">禁用</option>
					</select>
					<i class="icon"></i>
				</div>
				<p class="text-right">
					带*项为必填选项
				</p>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script>
		layui.use('global', function() {
			set_return_url(null);
			set_val('eq_is_del', '{$eq_is_del}');
			var fn = {
				import_user : function() {
					window.open("{:url('import')}", "_self");
					return false;
				},
				sync_to_weixin : function() {
					winopen("{:url('sync_to_weixin')}", 560, 470);
				},
				reset_password : function() {
					if ($("input[name='user_id[]']:checked").length == 0) {
						layer.msg('请选择要修改密码的人员 ');
						return;
					}
					winopen("{:url('password')}", 560, 470);
				},
				reset_salary_password : function() {
					if ($("input[name='user_id[]']:checked").length == 0) {
						layer.msg('请选择要重置工资密码的人员 ');
						return;
					}
					var vars = $("#form_user").serialize();
					layer.msg('确定重置工资密码?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							send_ajax("{:url('reset_salary_password')}", vars, function(data) {
								if (data.status) {
									layer.msg(data.info);
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},
				add : function() {
					winopen("{:url('add')}", 560, 470);
				},
				save : function() {
					send_form("form_data", "{:url('save')}", "{:url('index')}", function(ret) {
						if (ret.status) {
							layer.msg(ret.info, {
								time : 1200
							}, function() {
								location.reload(true);
							});
						} else {
							layer.msg(ret.info);
							return false;
						}
					});
				},
				del : function() {
					if ($("input[name='user_id[]']:checked").length == 0) {
						layer.msg('请选择要删除的人员 ');
						return;
					}
					//信息框-例2
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							var vars = $("#form_user").serialize();
							send_ajax("{:url('del')}", vars, function(ret) {
								if (ret.status) {
									layer.msg(ret.info, {
										time : 1200
									}, function() {
										location.reload(true);
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},
				select_avatar : function() {
					if ($("#id").val().length == 0) {
						layer.msg("请选择用户");
						return false;
					}
					winopen("{:url('popup/avatar')}?id=" + $("#id").val(), 560, 470);
				},
				select_dept : function() {
					winopen("{:url('select_dept')}", 560, 470);
				}
			};
			win_exp(fn);

			$(".table li.tbody").click(function() {
				$(".table li.active").removeClass("active");
				$this = $(this);
				$this.addClass("active");
				if ($(".table li.active input:checked").length == 0) {
					$(".table li.active input").prop('checked', true);
				} else {
					$(".table li.active input").prop('checked', false);
				}
				var vars = {};
				vars.id = $this.attr("data");
				send_ajax("{:url('read')}", vars, function(data) {
					show_data(data);
				});
				return false;
			});

			function show_data(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				var dept_id = $("#dept_id").val();
				var dept_name = $("#dept_list option[value='" + dept_id + "']").text();
				$("#dept_name").val(dept_name);

				$('#pic').attr('src', result.data.pic);
				$("#save_name").val("");
				$("#opmode").val("edit");
			};

			$("#eq_is_del").on('change', function() {
				$("#form_adv_search").submit();
			});
		});

	</script>
</block>
